package testJdk.thread.timer;

import java.text.DateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @version 1.0.0
 * Created by cyd on 2023-07-11 10:56:09
 * @ClassName : testJdk.thread.timer.TestTimer
 * @Description : 类描述
 */
public class TestTimer {

    public static void main(String[] args) {
        System.out.println("当前时间:" + DateFormat.getDateTimeInstance().format(new Date()));

        //延时方法三
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.print("----时间： " + DateFormat.getDateTimeInstance().format(new Date()));
                this.cancel();
            }
        }, 3000);
        System.out.print("三秒后打印时间:");
    }

}
